package dev.polls.skycube;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.jibble.simpleftp.*;

import android.content.SharedPreferences;
import android.util.Log;


public class UploadFtp {
	GroupId gi = new GroupId();

	public void ftpUpload(String filepath,String newFilename)
	{
	try {
	    SimpleFTP ftp = new SimpleFTP();
	    
	    // Connect to an FTP server on port 21.
	    ftp.connect("ftp.cyan.mysitehosted.com", 21, "androidupload", "uploadtest");
	    
	    // binary mode, is nodig voor images
	    ftp.bin();
	    	    
	    // file uploaden met inputstream
	    ftp.stor(new FileInputStream(new File(filepath)), newFilename);
	    
			
			
			HttpClient httpclient = new DefaultHttpClient();
		    HttpPost httppost = new HttpPost("http://skycube.eu/android/newimage?username=petertje&password=hallox&groupid="+gi.getGroupid()+"&title=Image&body=niets&link="+newFilename);
		   try {
		HttpResponse response = httpclient.execute(httppost);
	} catch (ClientProtocolException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	    // ftp afsluiten (uitloggen)
	    ftp.disconnect();
	}
	catch (IOException e) {
	   System.out.println("error");
	}
}
}